#line 5 "TheAlmostLuckyNumbersDivOne.cpp"
#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<iostream>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
ll dp[21][2][21][2];
int a[23], len;
ll getdp (int l, int less, int num, int zero)
{
    if (l == len) return num <= 1;

    if (dp[l][less][num][zero] != -1) return dp[l][less][num][zero];

    if (num > 1) return 0;

    int u;

    if (less) u = 9;
    else u = a[l];

    int i;
    ll res = 0;

    for (i = 0; i <= u; i++) {
        if (i == 0) {
            if (zero) {
                res += getdp (l + 1, less || i < a[l], num, zero);
            } else {
                res += getdp (l + 1, less || i < a[l], num + 1, zero);
            }
        } else {
            if (i == 4 || i == 7) {
                res += getdp (l + 1, less || i < a[l], num, 0);
            } else {
                res += getdp (l + 1, less || i < a[l], num + 1, 0);
            }
        }
    }

    return dp[l][less][num][zero] = res;
}
ll gao (ll x)
{
    len = 0;

    while (x) {
        a[len++] = x % 10;
        x /= 10;
    }

    reverse (a, a + len);
    memset (dp, -1, sizeof (dp) );
    return getdp (0, 0, 0, 1);
}
class TheAlmostLuckyNumbersDivOne
{
public:
    long long find (long long a, long long b) {
        return gao (b) - gao (a - 1);
    }


};
